package com.ruoyi.web.group.teams.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.group.teams.entity.Teams;
import com.ruoyi.web.group.teams.service.TeamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("team")
public class TeamsController {
    @Autowired
    private TeamsService teamsService;
    /**
     * 删除球队信息
     * @param id
     * @return
     */
    @GetMapping("del")
    public AjaxResult del(@RequestParam Integer id){

        if(id != null &&  teamsService.removeById(id)){
            return AjaxResult.success("操作成功");
        }
        return AjaxResult.error("操作失败");
    }

    /**
     * 添加球队
     * @param teams
     * @return
     */
    @PostMapping("add")
    public AjaxResult add(@RequestBody Teams teams){

        if(teams != null ){
            teams.setCreatedAt(new Date());
            if(teamsService.save(teams)){
                return AjaxResult.success("操作成功");
            }
        }
        return AjaxResult.error("操作失败");
    }

    /**
     * 修改球队信息
     * @param teams
     * @return
     */
    @PostMapping("upd")
    public AjaxResult upd(@RequestBody Teams teams){

        if(teams != null &&  teamsService.updateById(teams)){
            return AjaxResult.success("操作成功");
        }
        return AjaxResult.error("操作失败");

    }

    /**
     * 查询球队列表
     * @return
     */
    @GetMapping("list")
    public AjaxResult findList(@RequestBody Teams teams){
        return AjaxResult.success(teamsService.findList( teams));
    }
}
